import request from '@/utils/request'
// import qs from 'qs'

export function getUserPagedList(query) {
  return request({
    url: '/api/identity/users_admin/',
    method: 'get',
    params: query
  })
}

export function getUser(id) {
  return request({
    url: `/api/identity/users_admin/${id}/`,
    method: 'get'
  })
}

export function createUser(data) {
  return request({
    url: `/api/identity/users_admin/`,
    method: 'post',
    data
  })
}

export function updateUser(id, data) {
  return request({
    url: `/api/identity/users_admin/${id}/`,
    method: 'put',
    data
  })
}

export function deleteUser(id) {
  return request({
    url: `/api/identity/users_admin/${id}/`,
    method: 'delete'
  })
}

export function changePassword(id, data) {
  return request({
    url: `/api/identity/users_admin/${id}/change_password`,
    method: 'put',
    data
  })
}

export function changeMyPassword(data) {
  return request({
    url: `/api/account/change_password/`,
    method: 'put',
    data
  })
}

export function getAssignableRoles() {
  return request({
    url: `/api/identity/users/assignable-roles`,
    method: 'get'
  })
}

export function getUserRoles(id) {
  return request({
    url: `/api/identity/users/${id}/roles`,
    method: 'get'
  })
}

export function setUserRoles(id, data) {
  return request({
    url: `/api/identity/users/${id}/roles`,
    method: 'put',
    data
  })
}

// export function resetAllPermissions(data) {
//   return request({
//     url: '/api/services/app/UserAdmin/ResetAllPermissionsAsync',
//     method: 'post',
//     data
//   })
// }

export function exportUser(query) {
  return request({
    url: '/api/identity/users/export',
    method: 'get',
    responseType: 'blob', // 表明返回服务器返回的数据类型
    headers: {
      'Content-Type': 'application/json',
      'Accept': 'application/json'
    },
    params: query
  })
}

export function getGroupList() {
  return request({
    url: `/api/identity/groups_admin/`,
    method: 'get'
  })
}

export function getUserMembersList(query) {
  return request({
    url: '/api/account/user_members_admin/',
    method: 'get',
    params: query
  })
}

export function getUserBalancesList(query) {
  return request({
    url: '/api/account/user_balances_admin/',
    method: 'get',
    params: query
  })
}

export function getPointBalancesList(query) {
  return request({
    url: '/api/point/point_users_admin/',
    method: 'get',
    params: query
  })
}

export function changeUserMember(data) {
  return request({
    url: `/api/account/change_user_member/`,
    method: 'post',
    data
  })
}

export function changeUserBalance(data) {
  return request({
    url: `/api/account/change_user_balance/`,
    method: 'post',
    data
  })
}

export function changeUserPoint(data) {
  return request({
    url: `/api/point/change_for_admin/`,
    method: 'post',
    data
  })
}
